<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var str = 'qoqw1eoqqqeqqqwoqw'

    // q 出现的次数 及位置
    var count = 0
    var index = str.indexOf('q')
    while(index !== -1) {
      count += 1
      console.log(index)

      index = str.indexOf('q', index + 1)
    }
    console.log('次数' + count)


    // var count = 0
    // var index = -1
    // do {
    //   index = str.indexOf('q', index + 1)
    //   if(index !== -1) {
    //     console.log(index)
    //     count += 1
    //   }
    // } while( index !== -1)
    // console.log('次数' + count)




  </script>
</body>
</html>